/*
 * Thread.h
 *
 *  Created on: 2010-8-11
 *      Author: stargui
 */

#ifndef THREAD_H_
#define THREAD_H_

namespace Common
{

typedef enum
{
	THREAD_STATUS_START = 0,
	THREAD_STATUS_RUNNING = 1,
	THREAD_STATUS_STOPPING = 2,
	THREAD_STATUS_STOPPED = 3,
} EnumThreadStatus;

class CThread
{
public:

	CThread();

	virtual ~CThread();

private:

	virtual void *ThreadFuncImpl(void) = 0;

	virtual void PreBeginThread(void);

	virtual void PostExitThread(void);

	static void *ThreadRoutine(void *param);

public:

	void Start(int stacksize = 0);

	void Stop();

	void InternalStop();

private:

	volatile EnumThreadStatus m_RunningStatus;

	bool m_InternalStop;
};

}

#endif /* THREAD_H_ */
